from fastapi import APIRouter, HTTPException, Depends

from database.database import Document, VectorEmbedding
from database.database_function import get_db


router = APIRouter()


@router.get("/statistics", summary="获取系统统计信息")
async def get_statistics(db= Depends(get_db)):
    try:
        doc_count = db.query(Document).count()
        vector_count = db.query(VectorEmbedding).count()
        return {
            "success": True,
            "statistics": {
                "total_documents": doc_count,
                "total_vectors": vector_count,
                "average_vectors_per_doc": round(vector_count / doc_count, 2) if doc_count > 0 else 0
            }
        }
    except Exception as e:
        raise HTTPException(status_code=500, detail=f"获取统计信息失败: {str(e)}")


